{extend name="public:body" /}

{block name="header"}
  <div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title" style="padding:10px 0;height:30px;">
      <li>提现列表</li>
    </ul>
  </div>
{/block}
{block name="body"}
  {include file="finance:publics" /}
  <div class="layui-card-body">
    <div class="layui-form search-form">
      <div class="layui-form-item">
        <div class="layui-input-inline">
          <select name="status">
            <option {$param.status == -1 ? 'selected' : ''} value="-1">全部状态</option>
            {foreach $select_list as $k => $v}
            <option {$param.status == $k ? 'selected' : ''} value="{$k}">{$v}</option>
            {/foreach}
          </select>
        </div>
        
        <div class="layui-input-inline">
          <input placeholder="请输入订单号搜索" value="{$param.order_no}" name="order_no" type="text" autocomplete="off" class="layui-input">
        </div>        
          <button type="button" onclick="formsearch()" class="layui-btn" autocomplete="off">搜索</button>
          <button type="button" class="layui-btn fright" id="down-menu-btn">批量操作</button>
          <div class="down-menu">
            <ul>
              <li onclick="statusUpdate(1)">通过审核</li>
              <li onclick="statusUpdate(2)">拒绝审核</li>
              <li onclick="deleted()">一键删除</li>
            </ul>
          </div>        
      </div>
    </div>
    <div class="total">
      <i class="layui-icon layui-icon-chart"></i> 当前页面总计：提取钻石数量：<span>{php}echo sprintf($cur_page_sum);{/php}</span> / 个
    </div>
    <div class="total mb__10">
      <i class="layui-icon layui-icon-chart"></i> 所有页面总计：提取钻石数量：<span>{php}echo sprintf($all_page_sum);{/php}</span> / 个
    </div> 
    <table class="layui-table table table-hover table-bordered table-list" id="menus-table" lay-size="sm">
      <thead>
        <tr>
          <th type="normal" width="40" class="tc">
            <input name="th-checkbox" type="checkbox" onchange="checkall()">
          </th>
          <th class="tc">用户ID</th>
          <th class="tc">订单号</th>
          <th class="tc">名字</th>
          <th class="tc">电话</th>          
          <th class="tc" >提现前余额</th>
          <th class="tc" >提现余额</th>
          <th class="tc" >提现后余额</th>
          <th class="tc" width="100">申请时间</th>
          <th class="tc" width="100">审核时间</th>
          <th class="tc">状态</th>
          <th class="tc" width="70">操作</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($list as $v){?>
          <tr>
            <td class="tc">
              <input value="{$v.id}" class="tr-checkbox" type="checkbox">
            </td>
            <td class="tc">{$v.uid}</td>
            <td class="tc">{$v.order_no}</td>
            <td class="tc">{$v.username}</td>
            <td class="tc">{$v.phone}</td>           
            <td class="tc" style="color: #009688">{$v.deal_before}</td>
            <td class="tc" style="color: #1E9FFF">{$v.deal_amount}</td>
            <td class="tc" style="color: #5FB878">{$v.deal_after}</td>
            <td class="tc">{$v.create_time}</td>
            <td class="tc">{$v.update_time}</td>
            <td class="tc" >
            {if $v.status == 0} <div>未审核</div>
            {elseif $v.status == 1 /} <div style="color: #FF5722">审核通过</div>
            {else /} <div style="color: #009688">拒绝审核</div>
            {/if}
            </td>
            <td class="tc">
              <a href="<?php echo url('audit',['id'=>$v['id']])?>">审核</a> |
              <a class="a-post" style="cursor: pointer;" post-msg="删除数据不可恢复，确认删除吗？" post-url="<?php echo url('delete', ['id'=>$v['id']])?>">删除</a>
            </td>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="12" class="tc">
            {$page|raw}
            <span>共{$count}条</span>
            <span>
              {$limit|raw}
            </span>
          </td>
        </tr>
      </tfoot>
    </table>
  </div>

  <script>
    var url   = "{:url('finance/withdrawal')}",
        gParam = {
          'page': "{$param.page}",
          'limit': "{$param.limit}",
          'order_no': "{$param.order_no}",
          'status': -2
        }

    // 搜索
    var formsearch = function() {
      var form  = $('.search-form [name]')
      form.each(function(index, ele) {
        var key = $(form[index]).attr('name')
        gParam[key] = $(this).val()
      })

      gParam['page'] = 1
      window.location.href = url + _671.paramFormat(gParam)
    }

    // 页面选择
    var selectlimit = function() {
      gParam['limit'] = $('[name=limit]').val()
      window.location.href = url + _671.paramFormat(gParam)
    }

    // 下拉菜单
    $('body').click(function() {
      $('.down-menu').css('display', 'none')
    })
    $('#down-menu-btn').click(function(e) {
      var show = $('.down-menu').css('display') == 'none' ? 'block' : 'none'
      $('.down-menu').css('display', show)
      e.stopPropagation()
    })

    // 全选
    var checkall = function() {
      var th = $('[name=th-checkbox]')[0].checked
      $('.tr-checkbox').each(function (index) {
          $('.tr-checkbox')[index].checked = th
      })
    }

    // 选项框操作
    $('.tr-checkbox').change(function() {
      var thchecked = false
      $('.tr-checkbox').each(function(index) {
        var checked = $('.tr-checkbox')[index].checked
        if (checked) {
          thchecked = true
          return ;
        }
      })
      $('[name=th-checkbox]')[0].checked = thchecked
    })

    // 设置选项id
    var getId = function() {
      var idString = ''
      $('.tr-checkbox').each(function(index) {
        var ele = $('.tr-checkbox')[index]
        if (ele.checked) {
          idString += $(ele).attr('value') + ','
        }
      })
      idString = idString.substring(0, idString.length-1)
      return idString
    }

    // 订单状态更新
    var statusUpdate = function(status) {
      var d = { status: status, id: getId() }
      _671.post("{:url('finance/status_update')}", d, function(res) {
        if (res.code == 200) {
          layer.msg(res.msg, { icon: 6, time: 1500 }, function() {
            window.location.reload()
          })
        } else {
          layer.msg(res.msg, { icon: 5, time: 1500 })
        }
      })
    }

    // 删除用户
    var deleted = function() {
      layer.confirm('删除数据不可恢复，确认删除吗？', {icon: 3, title:'提示'}, function(index){
        var d = { id: getId() }
        _671.post("{:url('delete')}", d, function(res) {
          if (res.code === 200) {
            layer.msg(res.msg, { icon: 6, time: 1500 }, function() {
              window.location.reload()
            })
          } else {
            layer.msg(res.msg, { icon: 5, time: 1500 })
          }
        })
        layer.close(index)
      })
    }
  </script>
{/block}
